﻿using Reggie.BLL.Facades;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Reggie.BLL.Entities;

namespace Reggie.Business.Tests
{
    
    
    /// <summary>
    ///This is a test class for tExpressionTest and is intended
    ///to contain all tExpressionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class tExpressionTest
    {
        /// <summary>
        /// A test for TryIt with null Pattern input.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void t_TryIt_NullPattern()
        {
            // input and expected valuess
            string pattern = null;
            string testString = "testString";

            // run the system under test
            ExpressionTest.TryIt(pattern, testString);
        }

        /// <summary>
        /// A test for TryIt with null TestString input.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void t_TryIt_TestString()
        {
            // input and expected valuess
            string pattern = "pattern";
            string testString = null;

            // run the system under test
            ExpressionTest.TryIt(pattern, testString);
        }

        /// <summary>
        ///A test for TryIt
        ///</summary>
        [TestMethod()]
        [HostType("Moles")]
        public void t_TryIt()
        {
            // input and expected valuess
            string pattern = "pattern";
            string testString = "testString";
            string expected = "anything will do";

            // mockup the RegExTest class
            bool tryPatternWasRun = false;
            Reggie.BLL.Entities.Moles.MRegExTest.AllInstances.TryPatternMatch = (RegExTest iTester) =>
                {
                    tryPatternWasRun = true;
                    Assert.AreEqual(testString, iTester.TestString, "wrong TestString");
                    Assert.AreEqual(pattern, iTester.Pattern, "wrong Pattern");
                    return expected;
                };

            // run the system under test
            string actual = ExpressionTest.TryIt(pattern, testString);
            Assert.AreEqual(expected, actual, "Wrong output");
            Assert.IsTrue(tryPatternWasRun, "TryPattern wasn't run");
        }
    }
}
